# -*- coding: utf-8 -*- 
from django.http import Http404 # wyjątek do podnoszenia jak mam zły dzi
from django.shortcuts import render_to_response
from django.shortcuts import get_object_or_404
from django.contrib.auth.decorators import login_required
from django.http import HttpResponseRedirect
from django.http import HttpResponse #potrzebny żeby ręcznie zrobić responsa do popupów
from django.utils.encoding import force_unicode #potrzebny żeby javascript nie krzyczał
from intraorg.members.models import *
from intraorg.projects.models import *
from django.contrib.auth.decorators import login_required

@login_required
def projects(request, **kwargs):
    projects = Project.objects.all().order_by("name")
    nissues = ProjectIssue.objects.count()
    if nissues == 0:
        nissues = None
    njobs = JobOffert.objects.count()
    if njobs == 0:
        njobs = None
    return render_to_response("projects/list.html", \
        {'projects':projects, 'nissues':nissues, 'njobs':njobs, })

@login_required
def project(request, id,**kwargs):
    project = get_object_or_404(Project,id=id)
    users = ProjectTeam.objects.all().filter(project = project)
    issues = ProjectIssue.objects.all().filter(project = project)
    jobs = JobOffert.objects.all().filter(project = project)
    return render_to_response("projects/project.html", \
        {'project':project, 'users':users, 'issues':issues, 'jobs':jobs, })

def jobrequests(request):
    jobs = JobRequest.objects.all()
    return render_to_response("projects/jobrequests.html", \
        {'jobs':jobs, })

def jobofferts(request):
    jobs = JobOffert.objects.all()
    return render_to_response("projects/jobofferts.html", \
        {'jobs':jobs, })

